const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
Page({
  data: {
    userInfo:'',
    page:1,
    pageSize:10,
    isEnd:false,
    lists:[],
    isloading:false,
    type:1,
    total:0,
    nums:0,
  },
  onLoad() {
    this.info()
  },
  onShow(){
    if(!wx.getStorageSync('logintoken')){
      app.ToLogin()
      return
    }
    this.setData({
      page:1,
      pageSize:10,
      isEnd:false,
      lists:[],
    })
    this.contentlist()
    this.contentlist1()

  },
  info(){
    Controller.info().then(res=>{
      if(res.data.baseData){
        this.setData({
          userInfo:res.data.baseData
        })
      }
    })
  },
  tabs(e){
    this.setData({
      type:e.currentTarget.dataset.type,
      page:1,
      pageSize:10,
      isEnd:false,
      lists:[],
    })
    this.contentlist()
  },
  cash(){
    wx.navigateTo({
      url: "/pages/Me/cash"
    })
  },
  contentlist1(){
    Controller.mySubordinateUser({page:this.data.page,pageSize:this.data.pageSize,isLeave:0}).then(res=>{
      this.setData({
        nums:res.data.baseData.totalRow
      })
    })
  },
  contentlist(){
    var data={
      page:this.data.page,
      pageSize:this.data.pageSize,
      isLeave:this.data.type==1?'':0
    }
    Controller.mySubordinateUser(data).then(res=>{
      if(res.data.baseData && res.data.baseData.list.length>0){
        this.setData({
          lists:this.data.lists.concat(res.data.baseData.list),
          total:res.data.baseData.totalRow
        })
      }
      if(res.data.baseData.lastPage){
        this.setData({
          isEnd:res.data.baseData.lastPage
        })
      }
      this.setData({
        isloading:false
      })
    })
  },
  onReachBottom(){
    if(this.data.isEnd){
      return
    }else{
      this.setData({
        page:this.data.page+1
      })
      this.contentlist()
    }
    
  },
  golink(e){
    if(!wx.getStorageSync('logintoken')){
      app.goLogin()
      return
    }
    var item=e.currentTarget.dataset.item;
    if(item.jobStatus==-1){
      wx.showModal({
        title: '',
        content: '该岗位已停止招聘',
        showCancel:false,
        success (res) {
          if (res.confirm) {
            console.log('用户点击确定')
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
      return
    }
    wx.navigateTo({
      url:e.currentTarget.dataset.url
    });
  },
  onPageScroll: function (e) { // 获取滚动条当前位置
    
  },
  onShareAppMessage: function (e) {
    
  },
  onShareTimeline: function(res){
    
  },

})